/**
 * Independent time operation tool to facilitate subsequent switch to dayjs
 */
import dayjs from 'dayjs';

const DATE_TIME_FORMAT = 'YYYY-MM-DD HH:mm:ss';
const DATE_FORMAT = 'YYYY-MM-DD';

export const formatToDateTime = (
  date: dayjs.Dayjs | undefined = undefined,
  format = DATE_TIME_FORMAT,
): string | undefined => {
  return date ? dayjs(date).format(format) : undefined;
};

export const formatToDate = (
  date: dayjs.Dayjs | undefined = undefined,
  format = DATE_FORMAT,
): string | undefined => {
  return date ? dayjs(date).format(format) : undefined;
};

export const dateUtil = dayjs;
